package com.cycle.community.util;

import com.cycle.community.entity.User;

/**
 * @author lenovo
 * @create 2022/8/15 22:03
 */
public class RedisKeyUtil {
    private static final String SPLIT = ":";
    //帖子 评论 统称为实体，要存实体的赞  前缀
    private static final String PREFIX_ENTITY_LIKE = "like:entity";

    private static final String PREFIX_USER_LIKE = "like:user";

    private static final String PREFIX_FOLLOWEE = "followee"; //关注人
    private static final String PREFIX_FOLLOWER = "follower"; //粉丝，统计方便

    private static final String PREFIX_KAPTCHA = "kaptcha";
    private static final String PREFIX_TICKET = "ticket";
    private static final String PREFIX_USER = "user";


    //某个实体的赞  实体类型和实体id
    // entityType 1:帖子 2:评论  与CommunityConstant的联动 ENTITY_TYPE_POST ENTITY_TYPE_COMMENT
    //likes:entity:entityType:entityId  -> set(userId)  集合想看到谁给我赞了
    public static String getEntityLikeKey(int entityType, long entityId) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    //某一个用户的赞
    //like:user:userId -> long
    public static String getUserLikeKey(long userid) {
        return PREFIX_USER_LIKE + SPLIT + userid;
    }

    //某个用户关注的实体   有序集合  now先后顺序列出来
    //followee:userId:entityType -> zset(entityId,now)
    public static String getFolloweeKey(long userId, int entityType) {
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    //某个实体拥有的粉丝  entityType:entityId唯一标识一个实体
    //follower:entityType:entityId -> zset(userId,now)
    public static String getFollowerKey(int entityType, long entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    //followee 目标  某个用户的关注了哪些人：包含userId，关注的实体类型，    set:实体id，关注时间
    //follower 粉丝  某个实体的粉丝：      包含实体类型，实体id，   set:被关注的粉丝的userId，关注时间


    /**
     * 登录验证码，辅助登录
     *
     * @param owner 用户临时凭证
     * @return
     */
    public static String getKaptchaKey(String owner) {
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

    //登录凭证
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    //用户
    public static String getUserKey(long userId) {
        return PREFIX_USER + SPLIT + userId;
    }


}
